<template>
  <view>
    <up-form labelPosition="top" labelWidth="600">
      <up-form-item label="姓名">
        <u-input
          v-model="temp.name"
          border="surround"
          placeholder="请输入姓名"></u-input>
      </up-form-item>
      <up-form-item label="手机号">
        <u-input
          v-model="temp.phone"
          border="surround"
          placeholder="请输入手机号"></u-input>
      </up-form-item>
      <up-form-item label="性别">
        <up-radio-group v-model="temp.gender">
          <up-radio label="男" name="男"></up-radio>
          <up-radio label="女" name="女"></up-radio>
        </up-radio-group>
      </up-form-item>
    </up-form>
    <up-button type="primary" @click="submit">提交</up-button>
  </view>
</template>

<script setup>
import { addApi, editApi } from "@/api/index";
const { temp, submit, rule, submitType } = useSubmit({
  addApi: addApi,
  editApi: editApi,
  addSuccess: (res) => {
    uni.$sc.getBackPage("loadList");
    uni.navigateBack({});
  },
  editSuccess: (res) => {
    uni.$sc.getBackPage("loadList");
    console.log("编辑成功", res);
    uni.navigateBack({});
  },
});
rule.value = {
  name: "@姓名|require",
  phone: "@手机号|require",
  gender: "@性别|require",
};
// submitType.value = "add"; // 设置提交类型为添加
onLoad((params) => {
  submitType.value = params.type || "add"; // 获取提交类型
});
</script>

<style lang="scss" scoped></style>
